package com.overlord.im.commons.message;

import io.netty.buffer.ByteBuf;

import java.io.IOException;

/**
 * @author wuwei
 * @className Protocol
 * @description
 * @date 2020/5/9 11:52
 **/
public interface Protocol extends ProtocolConstant {

    /**
     * 编码
     * ++++|--------------------------------------------------------------------------------------|+
     * ++++|magic_word|version|sequence_id|message_type|  ack_type| system_type |length|content|+
     * ++++|    byte  |  byte |    long   |     byte   |    byte  |     byte    |medium|content|+
     * ++++|--------------------------------------------------------------------------------------|+
     *
     * @param out
     * @param message
     * @throws IOException
     */
    void encode(final ByteBuf out, final OverlordImMessage message) throws IOException;

    /**
     * 解码
     *
     * @param in
     * @return
     * @throws IOException
     */
    OverlordImMessage decode(ByteBuf in) throws IOException;
}
